home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Panorama / Panorama - Disk 30B (1988-06-08)(Pacific North-West Amigas Club)[WB].zip / Panorama - Disk 30B (1988-06-08)(Pacific North-West Amigas Club)[WB].adf / DNet1.20 / server / scli.c < prev    next >
C/C++ Source or Header  |  1988-03-22  |  2KB  |  101 lines

  1.  
  2. /*
  3.  *  S_SHELL.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  SHELL SERVER.   THIS REQUIRES MY PIPE DEVICE TO WORK!!!!!!!!!!
  8.  *
  9.  *  Use DSOC on the UNIX end (DSOC 8193)
  10.  *
  11.  *  Only one connection accepted at a time in this baby.
  12.  *  HUGE CLUDGE!!!
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <fcntl.h>
  17.  
  18. int Enable_Abort;
  19. char Buf[4096];
  20.  
  21. typedef struct Process PROC;
  22.  
  23. extern struct MsgPort *DListen();
  24. extern PROC *FindTask();
  25.  
  26. _main()
  27. {
  28.     struct MsgPort *port;
  29.     PROC    *proc = FindTask(NULL);
  30.     long    chan;
  31.     long    mask, rmask;
  32.     long    len, n;
  33.     char    nl, co;
  34.     int     fd;
  35.     long    namei = (long)proc;
  36.     APTR    oldwptr;
  37.  
  38.     Enable_Abort = 0;
  39.     port = DListen(8196);
  40.     WaitPort(&proc->pr_MsgPort);
  41.     ReplyMsg(GetMsg(&proc->pr_MsgPort));
  42.     if (!port)
  43.     exit(1);
  44.     mask = SIGBREAKF_CTRL_C|(1 << port->mp_SigBit);
  45.     oldwptr = proc->pr_WindowPtr;
  46.     proc->pr_WindowPtr = (APTR)-1;
  47.     for (;;) {
  48.     rmask = Wait(mask);
  49.     if (rmask & SIGBREAKF_CTRL_C)
  50.         break;
  51.     if (chan = DAccept(port)) {
  52.         long fh;
  53.         long mask;
  54.         long fhmask, smask;
  55.         short sig;
  56.         char pname[16];
  57.         char buf[64];
  58.  
  59.         sprintf(pname, "%08lx", namei++);
  60.         sprintf(buf, "newcli <nil: >nil: pipe:%s/t", pname);
  61.         Execute(buf, NULL, NULL);
  62.         sig = AllocSignal(-1);
  63.         fhmask = 1 << sig;
  64.         smask = 1 << ((struct MsgPort *)chan)->mp_SigBit;
  65.         sprintf(buf, "pipe:%s/tns%ld", pname, sig);
  66.         fh = Open(buf, 1006);
  67.         if (fh) {
  68.         char notdone = 1;
  69.         DWrite(chan, "Amiga CLI   running\n", 20);
  70.         while (notdone) {
  71.             char buf[256];
  72.             int n;
  73.             mask = Wait(fhmask | smask | SIGBREAKF_CTRL_C);
  74.             while ((n = Read(fh, buf, 256)) > 0) {
  75.             DWrite(chan, buf, n);
  76.             }
  77.             if (n < 0)
  78.             notdone = 0;
  79.             while ((n = DNRead(chan, buf, 256)) > 0) {
  80.             DWrite(chan, buf, n);
  81.             Write(fh, buf, n);
  82.             }
  83.             if (n < 0)
  84.             notdone = 0;
  85.         }
  86.         Write(fh, "ENDCLI\n", 7);
  87.         Write(fh, "ENDCLI\n", 7);
  88.         Close(fh);
  89.         }
  90.         DClose(chan);
  91.         FreeSignal(sig);
  92.         puts("DONE");
  93.     }
  94.     }
  95.     proc->pr_WindowPtr = oldwptr;
  96.     DUnListen(port);
  97. }
  98.  
  99.  
  100.  
  101.